home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / OrdColl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  4.9 KB  |  172 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OrdColl.h
  3.  
  4.     Contains:    Definition of class OrderedCollection
  5.  
  6.     Owned by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     
  11.     In Progress:
  12.         
  13. */
  14.  
  15. #ifndef _ORDCOLL_
  16. #define _ORDCOLL_
  17.  
  18. #ifndef _ODTYPES_
  19. #include "ODTypes.h"
  20. #endif
  21.  
  22. #ifndef _PLFMDEF_
  23. #include "PlfmDef.h"
  24. #endif
  25.  
  26. #ifndef _LINKLIST_
  27. #include "LinkList.h"
  28. #endif
  29.  
  30. #ifndef _ODMEMORY_
  31. #include "ODMemory.h"
  32. #endif
  33.  
  34. //==============================================================================
  35. // Theory of Operation
  36. //==============================================================================
  37.  
  38. // OrdereCollection is an ordered collection of elements of type void* (since
  39. // we can't use templates)
  40. // Duplicates are allowed.
  41.  
  42. //==============================================================================
  43. // Constants
  44. //==============================================================================
  45.  
  46. //==============================================================================
  47. // Scalar Types
  48. //==============================================================================
  49.  
  50. typedef void* ElementType;
  51.  
  52. //=====================================================================================
  53. // Classes defined in this interface
  54. //=====================================================================================
  55.  
  56. class OrderedCollection;    // An ordered (not sorted) collection of ElementTypes
  57. class OrderedCollectionIterator;
  58.  
  59. //=====================================================================================
  60. // Classes used by this interface
  61. //=====================================================================================
  62.  
  63. class ValueLink;             // A link plus a value of type ElementType.
  64.  
  65. //=====================================================================================
  66. // Global Variables
  67. //=====================================================================================
  68.  
  69. //=====================================================================================
  70. // Class ValueLink - Definition
  71. //=====================================================================================
  72.  
  73. class ValueLink : public Link {
  74.     
  75. public:
  76.                             ValueLink(ElementType value);        
  77.     ODVMethod                ~ValueLink();
  78.     ODNVMethod    ElementType    GetValue()                        { return fValue;}
  79.     ODNVMethod void        SetValue(ElementType v)            { fValue = v;}
  80.  
  81. private:
  82.     ElementType         fValue;
  83. };
  84.  
  85. //=====================================================================================
  86. // Class OrderedCollection
  87. //=====================================================================================
  88.  
  89. class OrderedCollection
  90. {
  91.     
  92. public:
  93.  
  94.     OrderedCollection();
  95.     OrderedCollection(ODMemoryHeapID where);
  96.     virtual ~OrderedCollection();
  97.  
  98.     ODNVMethod ODULong Count() const             { return fImplementation.Count(); };
  99.     
  100.     ODVMethod void    AddFirst(ElementType element);
  101.     ODVMethod void    AddLast(ElementType element);
  102.     ODVMethod void    AddBefore(ElementType existing, ElementType tobeadded);
  103.     ODVMethod void    AddAfter(ElementType existing, ElementType tobeadded);
  104.  
  105.     ODVMethod ElementType    After(ElementType existing) const;
  106.     ODVMethod ElementType    Before(ElementType existing) const;
  107.  
  108.     ODVMethod ElementType    First() const;
  109.         // Returns kODNULL if there is no first element.
  110.     ODVMethod ElementType    Last() const;
  111.  
  112.     ODVMethod ElementType    RemoveFirst();
  113.         // Don't call if there are no elements. Crash will result.
  114.     ODVMethod ElementType    RemoveLast();
  115.     ODVMethod void    RemoveAll();
  116.     
  117.         // Called from the destructor. Removes all elements, deleting the links
  118.         // Does not delete the elements themselves
  119.         
  120.     ODVMethod void    DeleteAll();
  121.     
  122.         // Removes and deletes all elements
  123.         
  124.     ODVMethod ODBoolean    Remove(ElementType existing);
  125.         // Returns true if existing was actually removed.
  126.         
  127.     ODVMethod ODBoolean    Contains(ElementType existing) const;
  128.     
  129.     ODVMethod OrderedCollectionIterator* CreateIterator();
  130.     
  131.     ODNVMethod ODMemoryHeapID GetHeap() const;
  132.  
  133. protected:
  134.      ODVMethod ValueLink*     CreateNewLink(ElementType value) const;
  135.      ODVMethod ODBoolean    ElementsMatch(ElementType v1,ElementType v2) const;
  136.          // Does a pointer comparison by default 
  137.  
  138. private:
  139.     LinkedList        fImplementation;
  140.     ODMemoryHeapID    fHeap; // if kODNULL, use default heap.
  141.  
  142.     friend class OrderedCollectionIterator;
  143.     friend class ListIterator;
  144. };
  145.  
  146. inline ODMemoryHeapID OrderedCollection::GetHeap() const 
  147. {
  148.     return fHeap;
  149. }
  150.  
  151.  
  152. //=====================================================================================
  153. // Class OrderedCollectionIterator
  154. //=====================================================================================
  155.  
  156. class OrderedCollectionIterator {
  157. public:
  158.     OrderedCollectionIterator(OrderedCollection* collection);
  159.     ~OrderedCollectionIterator();
  160.     ElementType First();
  161.     ElementType Next();
  162.     ElementType Last();
  163.     ElementType Previous();
  164.     ODBoolean   IsNotComplete();
  165.     void        RemoveCurrent();
  166.     
  167. private:
  168.       OrderedCollection*    fCollection;
  169.     LinkedListIterator    fImplementation;
  170. };
  171.  
  172. #endif // _ORDCOLL_